<?php
/**

 */
define('IN_DOUCO', true);

// 强制在移动端中显示PC版
if (isset($_REQUEST['mobile'])) {
   setcookie('client', 'pc');
   if ($_COOKIE['client'] != 'pc') $_COOKIE['client'] = 'pc';
}

require (dirname(__FILE__) . '/include/init.php');

// 如果存在搜索词则转入搜索页面
if ($_REQUEST['search']) {
    if ($check->is_search_keyword($keyword = trim($_REQUEST['search']))) {
        require (ROOT_PATH . 'include/search.inc.php');
    } else {
        $dou->dou_msg($_LANG['search_keyword_wrong']);
    }
}

if ($_REQUEST['lang']) {
    $lang = $_REQUEST['lang'];
}else{
    $lang = 'zh';
}
require (dirname(__FILE__) . '/common.php');

$smarty->assign('dangqun_url', get_dangqun($lang));
$smarty->assign('zhaosheng_url', get_zhaosheng($lang));


if ($_REQUEST['type']) {
    $type = $_REQUEST['type'];
}else{
    $type = '1';
}

if ($_REQUEST['cat_id']){
    $cat_id = $_REQUEST['cat_id'];
}else{
    $cat_id = '1';
}

// $query = $dou->select(
//             $dou->table('product')
//             , '*'
//             , '`cat_id` = \'' . $cat_id . '\' and `lang` = \'' . $lang . '\'' 
//         );

// $product = $dou->fetch_array($query);

$products = $dou->get_list('product', $cat_id, '', 'sort DESC');

$where = ' WHERE cat_id IN (' . $cat_id . ') and lang=\''. $lang.'\'';

$sql = "SELECT id, cat_id, rgcat_id, name, keywords, description FROM " . $dou->table('product') . $where . " ORDER BY rgcat_id, name ";
$query = $dou->query($sql);

while ($row = $dou->fetch_array($query)) {
    $url = 'info.php?type=1&id='.$row['id'];
    $add_time = date("Y-m-d", $row['add_time']);
    

    $childsql = "SELECT id, name FROM " . $dou->table('group') . " where id=". $row['rgcat_id'];
    $childquery = $dou->query($childsql);

    $group = $dou->fetch_array($childquery);

    $products_list[] = array (
            "id" => $row['id'],
            "cat_id" => $row['cat_id'],
            "keywords" => $row['keywords'],
            "group" => $group['name'],
            "name" => $row['name'],
            "description" => $row['description'],
            "url" => $url 
    );
}

// $smarty->assign('test', $childsql);

$smarty->assign('products_list', $products_list);
$smarty->assign('lang', $lang);


$smarty->display('table.dwt');


?>
